const {Craw,rize} = require('../app')
const req = new Craw({url:'https://lists.meizu.com/page/list?categoryid=76&click=gw_index_cdh_1'});

async function iphone_() {
    await req.sleep(1500);
    await rize.click('#slProp > div:nth-child(1) > div.mod-value > div > ul > li.vm-all > a')
    await req.sleep(500);
    await rize.click('#slProp > div:nth-child(2) > div.mod-value > div > ul > li.vm-all > a')
    await req.sleep(500);
    await rize.click('#slProp > div:nth-child(3) > div.mod-value > div > ul > li.vm-all > a')
    console.log('获取数据完毕，返回数据')
    return Promise.resolve(iphoneData())
}
iphone_()

async function iphoneData() {
    let data = await req.PageDown({
        fnc:function () {
            let li = document.querySelectorAll('#goodsListWrap > li > a > div');
            let arr = [];
            [].forEach.call(li,(item,index) => {
                let imgUrl = item.querySelector('.mod-pic img').src.replace(/@.+$/g,'');

                let img = [].map.call(item.querySelectorAll('.item-slide img'), (dom,num) => {
                    let i =num;
                    let obj = {};
                    obj[`imgWrap_${i}`] = dom.src.replace(/@.+$/g,'');
                    return obj
                })

                let iphomeNmae = item.querySelector('h2').innerText;
                let describe = item.querySelector('h3').innerText;
                let price = item.querySelector('.vm-price').innerText;

                arr.push({imgUrl,imgWrap:img,iphomeNmae,describe,price});
            })
            return arr
        }
    })
    return data
}


exports.iphone = iphone_;

